<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="UTF-8">
  <title>修改用户信息</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      padding: 20px;
    }

    .container {
      max-width: 600px;
      margin: auto;
      background: #fff;
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }

    h1 {
      text-align: center;
      color: #333;
    }

    label {
      display: block;
      margin-bottom: 5px;
      font-weight: bold;
    }

    input[type="text"],
    input[type="password"] {
      width: 100%;
      padding: 10px;
      margin-bottom: 20px;
      border: 1px solid #ccc;
      border-radius: 4px;
      font-size: 16px;
    }

    button {
      width: 100%;
      padding: 10px;
      background-color: #28a745;
      border: none;
      border-radius: 4px;
      color: white;
      font-size: 16px;
      cursor: pointer;
      transition: background-color 0.3s;
    }

    button:hover {
      background-color: #218838;
    }

    .message {
      text-align: center;
      margin: 20px 0;
    }

    .message p {
      padding: 10px;
      border-radius: 4px;
    }

    .message.success {
      background-color: #d4edda;
      color: #155724;
    }

    .message.error {
      background-color: #f8d7da;
      color: #721c24;
    }

    a {
      display: block;
      text-align: center;
      margin-top: 20px;
      color: #007bff;
      text-decoration: none;
    }

    a:hover {
      text-decoration: underline;
    }
  </style>
</head>

<body>
<div th:if="${session.user}">
  <div class="container">
    <h1>修改用户信息</h1>
    <p>用户 ID: <span th:text="${session.user.userid}"></span></p>
    <form th:action="@{/personalhomepage/reviseuser}" method="post">
      <input type="hidden" name="userId" th:value="${session.user.userid}" />

      <label for="username">用户名：</label>
      <input type="text" id="username" name="username" th:value="${session.user.username}" required>

      <label for="password">密码：</label>
      <input type="password" id="password" name="password" required>

      <label for="gender">性别：</label>
      <input type="text" id="gender" name="gender" th:value="${session.user.usersex}" required>

      <label for="phone">电话：</label>
      <input type="text" id="phone" name="phone" th:value="${session.user.phone}" required>

      <label for="email">邮箱：</label>
      <input type="text" id="email" name="email" th:value="${session.user.email}" required>

      <button type="submit" id="tijiao">提交修改</button>
    </form>

    <div class="message" th:if="${message}">
      <p class="success" th:text="${message}"></p>
    </div>
    <div class="message" th:if="${error}">
      <p class="error" th:text="${error}"></p>
    </div>

    <a href="/personalhomepage">返回用户个人页面</a>
  </div>
</div>
</body>
<script>
  $('#tijiao').click(function (e) {
    e.preventDefault(); // 阻止链接默认跳转行为

    // 弹出询问确定窗口
    if (confirm("你确定要修改个人信息吗？")) {
      // 如果用户点击确定，继续执行删除操作
      window.location.href = $(this).attr('href');
    }
  });
</script>
</html>